package com.itheima.mm.controller;

import com.itheima.mm.dao.TagDao;
import com.itheima.mm.entity.PageResult;
import com.itheima.mm.entity.QueryPageBean;
import com.itheima.mm.entity.Result;
import com.itheima.mm.pojo.Catalog;
import com.itheima.mm.pojo.Course;
import com.itheima.mm.pojo.Tag;
import com.itheima.mm.service.TagService;
import com.itheima.mm.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/tag")
public class TagController {
    @Autowired
    private TagService tagService;
    @PostMapping("/findListByPage")
    public Result findListByPage(@RequestBody QueryPageBean queryPageBean){
        List<Tag> courseList= tagService.findListByPage(queryPageBean);
        /*获取所有题目的问题*/
        Long total = tagService.findTotal(queryPageBean);
        return new Result(true,"获取题目列表成功",new PageResult(total,courseList));
    }

    @GetMapping("/delete")
    public Result delete(@RequestParam("tagId") Integer tagId){
        tagService.delete(tagId);
        return new Result(true,"删除成功");
    }
    @PostMapping("/add")
    public Result add(@RequestBody Tag tag){
        tag.setUserId(1);
        tag.setOrderNo(1);
        tag.setStatus(0);
        tag.setCreateDate(DateUtils.parseDate2String(new Date()));
        tagService.add(tag);
        return new Result(true,"添加成功");
    }

}
